package com.yupi.yupicturebackend.manager.websocket.ws;

import cn.hutool.json.JSONUtil;
import com.yupi.yupicturebackend.manager.websocket.PictureEditHandler;
import com.yupi.yupicturebackend.manager.websocket.model.PictureEditMessageTypeEnum;
import com.yupi.yupicturebackend.manager.websocket.model.PictureEditRequestMessage;
import com.yupi.yupicturebackend.manager.websocket.model.PictureEditResponseMessage;
import com.yupi.yupicturebackend.model.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

@Component("default")
public class DefaultMessageHandler extends BaseMessageHandler {
    @Override
    public void handle(PictureEditRequestMessage request,
                       WebSocketSession session,
                       User user,
                       Long pictureId,
                       PictureEditHandler context) throws Exception {
        PictureEditResponseMessage response = new PictureEditResponseMessage();
        response.setType(PictureEditMessageTypeEnum.ERROR.getValue());
        response.setMessage("不支持的消息类型");
        response.setUser(userService.getUserVO(user));
        session.sendMessage(new TextMessage(JSONUtil.toJsonStr(response)));
    }
}